# $Id: PKGBUILD 73502 2012-07-08 17:57:22Z spupykin $
# Maintainer: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Jens Pranaitis <jens@jenux.homelinux.org>

pkgname=busybox
pkgver=1.20.2
pkgrel=1.5
pkgdesc="Utilities for rescue and embedded systems(binary only)"
arch=("sh4")
url="http://www.busybox.net"
license=('GPL')
makedepends=("make" "gcc" "sed" "ncurses")
source=($url/downloads/$pkgname-$pkgver.tar.bz2
	config
	busybox_rmlink.sh
	mdev.conf
        default.script
	)
provides=(vi cron sed which dhcpcd)
install=busybox.install

build() {
  cd "$srcdir/$pkgname-$pkgver"
  cp $srcdir/config .config
  sed '1,1i#include <sys/resource.h>' -i include/libbb.h
  # if you want to run menuconfig uncomment the following line:
#  make menuconfig ; return 1
  make oldconfig
  make LDFLAGS=-lm
}

package() {
  local f
  cd "$srcdir/$pkgname-$pkgver"
  #install -Dm755 busybox $pkgdir/bin/busybox
  make install
  mkdir -p $pkgdir/bin
  cp -r pkg/* $pkgdir
  cp $srcdir/busybox_rmlink.sh $pkgdir/bin

  mkdir -p $pkgdir/etc
  cp $srcdir/mdev.conf $pkgdir/etc

  mkdir -p $pkgdir/usr/share/udhcpc
  cp $srcdir/default.script $pkgdir/usr/share/udhcpc/default.script

  rm $pkgdir/bin/sh # prevent conflict with 'bash'
  for f in dmesg kill more mount mountpoint tar umount dnsdomainname hostname \
    ping ping6 ps
  do
    rm $pkgdir/bin/$f
  done
  for f in blkid blockdev findfs fsck.minix hwclock losetup mke2fs mkfs.ext2 \
      mkfs.minix mkswap pivot_root swapoff swapon switch_root sysctl ; do
    rm $pkgdir/sbin/$f
  done

  # prevent conflict with util-linux, binutils, wget & patch
  for f in bunzip2 bzcat bzip2 chrt eject flock hexdump ipcrm ipcs logger \
      lzcat lzma mesg renice script setsid timeout unlzma unxz wall xz xzcat \
      patch strings wget ar cmp telnet less free pgrep pkill \
      pmap pwdx top uptime fuser lsusb
  do
    rm $pkgdir/usr/bin/$f
  done
  for f in ftpd telnetd readprofile ; do
    rm $pkgdir/usr/sbin/$f
  done

  # prevent conflict with sysvinit-tools
  rm $pkgdir/bin/pidof $pkgdir/usr/bin/killall5 $pkgdir/usr/bin/last 

  # prevent conflict with psmisc
  for f in killall pstree ; do rm $pkgdir/usr/bin/$f ; done

  # prevent conflict with sysvinit
  for f in halt init poweroff reboot runlevel ; do rm $pkgdir/sbin/$f ; done
}

md5sums=('e025414bc6cd79579cc7a32a45d3ae1c'
         '36b485edc83f95c66c3791ca3030ac97'
         'a4f9fd450912857777a3c71cf6aab144'
         '552ff4c55908d0bfd6563618e8be3321'
         '0869726c3fdd7a10f9ea5b368a9474a0')
